//
//  ColorManager.m
//  homework-04
//
//  Created by dllo on 16/7/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ColorManager.h"

@implementation ColorManager
- (instancetype)initWithDictionary:(NSMutableDictionary *)dictionary{
    self = [super init];
    if (self) {
        _firstDictionary = dictionary;
        _secondeDictionary = dictionary;
    }
    return self;
}
//添加到同一个字典中
- (void)addColor:(NSArray *)colorArray {
    for (int i = 0; i < colorArray.count - 1; i++) {
        NSArray *separatorColor = [colorArray[i] componentsSeparatedByString:@" #"];
    [self.firstDictionary setObject:[separatorColor lastObject] forKey:[separatorColor firstObject]];
    }
}
//分组添加
- (void)addColorGroup:(NSArray *)colorArray {
    for (int i = 0; i < colorArray.count - 1; i++) {
       NSArray *separatorColor = [colorArray[i] componentsSeparatedByString:@" #"];
        NSString *firstCharacter = [[separatorColor[0] substringToIndex:1] capitalizedString];
        NSMutableArray *arr = [self.secondeDictionary objectForKey:firstCharacter];
        if (arr == nil) {
            arr = [NSMutableArray array];
            Color *color = [[Color alloc] initWithColorName:separatorColor[0] sixteenAry:separatorColor[1]];
            [arr addObject:color];
            [self.secondeDictionary setObject:arr forKey:firstCharacter];
        } else {
            Color *color = [[Color alloc] initWithColorName:separatorColor[0] sixteenAry:separatorColor[1]];
            [arr addObject:color];
            [self.secondeDictionary setObject:arr forKey:firstCharacter];
        }
    }

}
@end
